package com.example.demo.controller;

import com.example.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.ArrayList;

@Controller
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/books")
    public String books() {
        return "books";
    }
    @GetMapping("/add-book")
    public String addBook() {
        return "add-book";
    }
    @PostMapping("/add-book")
    public String addBook(String title, String desc, double price) {
        bookService.addBook(title, desc, price);
        return "redirect:/books";
    }
    @GetMapping("/delete-book")
    public String deleteBook(int bid) {
        bookService.deleteBook(bid);
        return "redirect:/books";
    }
}
